package com.desktopmng.common;

import java.util.List;

import javax.servlet.http.HttpSession;

import com.desktopmng.core.DesktopBean;
import com.desktopmng.core.ServiceManager;
import com.desktopmng.exception.JFossException;
import com.desktopmng.orm.UserConfig;
import com.desktopmng.service.DesktopContentManager;
import com.desktopmng.service.UserConfigManager;

public class JfossAjaxInvokeService {

	private DesktopContentManager desktopContentManager = (DesktopContentManager) ServiceManager
			.getBean("desktopContentManager");

	private UserConfigManager userConfigManager = (UserConfigManager) ServiceManager
			.getBean("userConfigManager");

	
	/**
	 * Description: 根据个人桌面内容Id获取显示内容对象
	 * 
	 * @param id
	 *            个人桌面内容Id
	 * @param userId
	 *            用户Id
	 * @return 个人桌面显示内容对象
	 * @throws JFossException
	 */
	public DesktopBean loadPersonalDesktop(Long id, Long userId)
			throws JFossException {

		DesktopBean obj = desktopContentManager.findDesktopBeanByDCId(id,
				userId);
		return obj;
	}
	
	/**
	 * Description: 获取系统信息数据统计列表
	 * 
	 * @param id
	 *            个人桌面内容Id
	 * @param userId
	 *            用户Id
	 * @return 系统信息数据统计列表
	 * @throws JFossException
	 */
	public List loadSystemMsgStat(Long id, Long userId) throws JFossException {

		List list = desktopContentManager.findSystemMsgStatList(id, userId);
		return list;
	}

	/**
	 * Description: 获取Session中用户配置对象
	 * 
	 * @param userConfigId
	 *            根据用户配置对象的ID 根据用户配置对象的ID更新该用户配置的布局信息 更新页面中Session储存的用户配置对象
	 * 
	 * @throws JFossException
	 */

	public void saveUserConfigLayOut(String layOut, String ids, HttpSession session) {

		UserConfig userConfig = (UserConfig) session.getAttribute("USERCONFIG");
		userConfig.setTemplate(layOut);
		session.setAttribute("USERCONFIG", userConfig);
		try {
			userConfigManager.updateUserConfig(userConfig, ids);
		} catch (JFossException e) {
			e.printStackTrace();
		}

	}
	
}
